#ifndef QSHAKE_H
#define QSHAKE_H

#include <QAccelerometer>
#include <QAccelerometerFilter>
#include <QAccelerometerReading>

QTM_USE_NAMESPACE

class QShake : public QObject, public QAccelerometerFilter
{
    Q_OBJECT
    Q_CLASSINFO("Author", "Sebastiano Galazzo")
    Q_CLASSINFO("Email", "sebastiano.galazzo@gmail.com")
    Q_PROPERTY(float sensitivity READ sensitivity WRITE setSensitivity)
    Q_PROPERTY(QShake::Direction direction READ direction WRITE setDirection)
    Q_ENUMS(Level)
    Q_ENUMS(Direction)

public:
    QShake(QObject * parent = 0 );

    enum Level {
        Low=20,
        Medium=30,
        High=40,
        Step=10
    };

    enum Direction {
        All=0,
        LeftRight=1,
        UpDown=2,
        PushPull=3
    };

    float sensitivity() const;
    void setSensitivity(float value);

    QShake::Direction direction() const;
    void setDirection(QShake::Direction value);

public slots:
    void start();
    void stop();

signals:
    void shake(bool shaked);

protected:
    bool filter(QAccelerometerReading *reading);

private:
    float module;
    float m_sensitivity;
    Direction m_direction;
    QAccelerometer sensor;
};

#endif // QSHAKE_H
